import 'dart:math';

import 'package:flutter/material.dart';
import 'package:pkg_obz/export.dart';

class ScrollViewSliverAppbar extends PageStateful<PageModel> {
  ScrollViewSliverAppbar({Key? key}) : super(key: key,tag: "ScrollViewSliverAppbar", pageModel: PageModel());

  List<Widget> get _defaultSlivers => [
        SliverAppBar(
          //扩展高度
          expandedHeight: 300,
          pinned: true,
          title: Text("TOP"),
          leading: new IconButton(
            icon: Icon(Icons.arrow_back),
            onPressed: () => ZRouter.goBack(),
          ),
          actions: <Widget>[
            new IconButton(
              icon: Icon(Icons.add),
              onPressed: () {
                print("添加");
              },
            ),
            new IconButton(
              icon: Icon(Icons.more_horiz),
              onPressed: () {
                print("更多");
              },
            ),
          ],
          flexibleSpace: FlexibleSpaceBar(
            title: Text("SliverAppBar"),
            centerTitle: true,
            background: Image.asset(
              "assets/images/abc.jpg",
              fit: BoxFit.fill,
            ),
          ),
        ),
        SliverGrid(
          delegate: SliverChildBuilderDelegate(
            (BuildContext ctx, int pos) {
              return Container(
                color: Color.fromARGB(177, Random().nextInt(256),
                    Random().nextInt(256), Random().nextInt(256)),
              );
            },
            childCount: 20,
          ),
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 2,
            childAspectRatio: 2,
            crossAxisSpacing: 8,
            mainAxisSpacing: 8,
          ),
        ),
      ];

  @override
  Widget rootView(BuildContext context) => Container(
        color: Colors.white,
        child: CustomScrollView(
          slivers: _defaultSlivers,
        ),
      );
}
